@extends('Layout/base')

@section('header-js')

	<!-- <link rel="stylesheet" type="text/css" href="{{ asset('css/app.css') }}"> -->
	<link rel="stylesheet" type="text/css" href="{{ asset('css/home.css') }}">
	<link rel="stylesheet" type="text/css" href="{{ asset('css/base.css') }}">
	<!-- <script type="text/javascript" src="{{ asset('js/jquery.js') }}"></script> -->
	<script type="text/javascript" src="{{ asset('js/js-tab.js') }}"></script>

@endsection


@section('content')

    <div class="yHeader">
        <div class="yNavIndex">
            <div class="pullDown">
                <h2 class="pullDownTitle">全部商品分类</h2>
            </div>
            <ul class="yMenuIndex">
                <li><a href="{{ route('Home.goodssale') }}" target="_blank">限时抢购</a></li>
								<li><a href="{{ route('Home.goodsList') }}">全部商品</a>
                @foreach($types as $v)
                <li><a href="{{ route('Home.goodsList', ['id' => $v['id']]) }}" target="_blank">{{ $v['type_name'] }}</a></li>
                @endforeach
            </ul>
        </div>
    </div>
</header>
<!-- header End -->

<div class="containers"><div class="pc-nav-item"><a href="#">首页 </a>
	@if(empty($typeName))
	&gt; <a href="#">所有商品</a></div></div>
	@else
	&gt; <a href="#">{{ $typeName }}</a></div></div>
	@endif
<div class="containers clearfix">
    <div class="fl">
        <div id="firstpane" class="menu_list">
            <h2>所有类目</h2>
				@foreach($types as $k => $type)
					@if($k == 0)
	            <h3 class="menu_head current">{{$type['type_name']}}</h3>
	            <div style="display:block" class="menu_body">
						@if(!empty($type['sons']))
							@foreach($type['sons'] as $sons)
	                <a href="{{ route('Home.goodsList', ['id' => $sons['id']])}}">{{ $sons['type_name'] }}</a>
							@endforeach
						@else
						<a href="#">暂无子分类</a>
						@endif
	            </div>
					@else
				<h3 class="menu_head">{{$type['type_name']}}</h3>
					<div style="display:none" class="menu_body">
						@if(!empty($type['sons']))
							@foreach($type['sons'] as $sons)
								<a href="{{ route('Home.goodsList', ['id' => $sons['id']])}}">{{ $sons['type_name'] }}</a>
							@endforeach
						@else
								<a href="#">暂无子分类</a>
						@endif
							</div>
							@endif
				@endforeach
        </div>
    </div>
    <div class="pc-info fr">
        <div class="pc-term">
            <dl class="pc-term-dl clearfix">
                <dt>品牌：</dt>
				@foreach($brands as $brand)
                <dd>
                	<a href="{{ route('Home.goodsList', ['brand_id' => $brand['id'], 'id' => $type_id]) }}">
						<img src="http://oydt3ttm3.bkt.clouddn.com/{{ $brand['brand_logo'] }}" width="100" height="50"/>
					</a>
				</dd>
				@endforeach
            </dl>
        </div>
        <div class="pc-term">
            <div class="clearfix pc-search-p">
                <div class="fl pc-search-e">
					@if (!empty($buy_num) && $buy_num == 'desc')
					<a href="{{ route('Home.goodsList', ['buy_num' => 'asc', 'id' => $type_id ])}}">↓销量</a>
					@elseif (!empty($buy_num) && $buy_num == 'asc')
					<a href="{{ route('Home.goodsList', ['buy_num' => 'desc', 'id' => $type_id ])}}">↑销量</a>
					@else
					<a href="{{ route('Home.goodsList', ['buy_num' => 'asc', 'id' => $type_id ])}}">销量</a>
					@endif

					@if (!empty($price) && $price == 'desc')
					<a href="{{ route('Home.goodsList', ['price' => 'asc', 'id' => $type_id])}}">↓价格</a>
					@elseif (!empty($price) && $price == 'asc')
					<a href="{{ route('Home.goodsList', ['price' => 'desc', 'id' => $type_id])}}">↑价格</a>
					@else
					<a href="{{ route('Home.goodsList', ['price' => 'asc', 'id' => $type_id])}}">价格</a>
					@endif

					@if (!empty($created_at) && $created_at == 'desc')
					<a href="{{ route('Home.goodsList', ['created_at' => 'asc', 'id' => $type_id])}}">↓上架时间</a>
					@elseif (!empty($created_at) && $created_at == 'asc')
					<a href="{{ route('Home.goodsList', ['created_at' => 'desc', 'id' => $type_id])}}">↑上架时间</a>
					@else
					<a href="{{ route('Home.goodsList', ['created_at' => 'asc', 'id' => $type_id])}}">上架时间</a>
					@endif

				</div>
				<div class="fl pc-search-in">
						<form action="{{ route('Home.goodsList')}}">
							{{csrf_field()}}
							<input type="hidden" name="id" value="{{$type_id}}"/>
							<input type="number" class="pc-search-s" placeholder="￥" min="0" name="p1">
							<input type="number" class="pc-search-s" placeholder="￥" min="0" name="p2">
							<button  class="pc-search-a" style="width:80px;border:1px solid black">搜索</button>
						</form>
				</div>
            </div>

        </div>
        <div class="time-border-list pc-search-list clearfix">
            <ul class="clearfix">
							@foreach($goods as $v)
								@if(count($goods) == 0)
								<li>
										<h1>暂无商品。</h1>
								</li>
								@else
                <li>
                    <a href="{{ route('goods.goodsdetail', ['id' => $v->id]) }}"> <div style="width:213px; height:213px"><img src="http://oydt3ttm3.bkt.clouddn.com/{{ $v->goods_pic }}" width="213"></div></a>
                    <p class="head-name"><a href="{{ route('goods.goodsdetail', ['id' => $v->id]) }}">{{ $v->goods_name }}</a> </p>
                    <p><span class="price">￥{{ $v->price }}</span></p>
                    <p class="head-futi clearfix"><span class="fr">{{ $v->buy_num }}人购买</span></p>
                    <p class="clearfix"><a href="{{ route('goods.goodsdetail', ['id' => $v->id]) }}"><span class="label-default fl">抢购</span></a>
                    	@auth()
												@stow($v->id)
												<a href="javascript:;" onclick="goodsStow(this, {{$v->id}})" class="fr pc-search-c">收藏</a>
												@elsestow
												<a href="javascript:;" class="fr pc-search-c">已收藏</a>
												@endstow
											@endauth
										</p>
                </li>
								@endif
							@endforeach
            </ul>
            <div class="clearfix">

				@if( !empty($brand_id) )

					{{ $goods->appends(['id' => $type_id, 'brand_id' => $brand_id] )->links('Home.GoodslistPage') }}

				@elseif ( !empty($buy_num) )

					{{ $goods->appends(['id' => $type_id, 'buy_num' => $buy_num] )->links('Home.GoodslistPage') }}

				@elseif ( !empty($price) )

					{{ $goods->appends(['id' => $type_id, 'price' => $price] )->links('Home.GoodslistPage') }}

				@elseif ( !empty($created_at) )

					{{ $goods->appends(['id' => $type_id, 'created_at' => $created_at] )->links('Home.GoodslistPage') }}

				@elseif ( !empty($p1) && empty($p2) || !empty($p2) && empty($p1) || !empty($p1) && !empty($p2))

					{{ $goods->appends(['id' => $type_id, 'p1' => $p1, 'p2' => $p2] )->links('Home.GoodslistPage') }}

				@else

					{{ $goods->appends(['id' => $type_id ] )->links('Home.GoodslistPage') }}

				@endif

            </div>
        </div>
    </div>
</div>

@endsection

@section('foot-js')
<script type="text/javascript">
		$(document).ready(function(){

				$("#firstpane .menu_body:eq(0)").show();
				$("#firstpane h3.menu_head").click(function(){
						$(this).addClass("current").next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
						$(this).siblings().removeClass("current");
				});

				$("#secondpane .menu_body:eq(0)").show();
				$("#secondpane h3.menu_head").mouseover(function(){
						$(this).addClass("current").next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("slow");
						$(this).siblings().removeClass("current");
				});

		});

		//ajax请求收藏商品,收藏成功后把标签改成已收藏
		function goodsStow(obj, goods_id){
			if(goods_id) {
				$.get('{{ route('addgoodsstow')}}', {'goods_id': goods_id}, function(data){
						if (data.status == 200) {
							str = '<a href="javascript:;" class="fr pc-search-c">已收藏</a>';
							$(obj).parent().append(str);
							$(obj).remove();
						}
				}, 'json');
			}
		};




</script>
@endsection
